 IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spFdsCNCreateUserHRDeptMap')
	BEGIN
		PRINT 'Dropping Procedure spFdsCNCreateUserHRDeptMap    '
		DROP  Procedure  spFdsCNCreateUserHRDeptMap    
	END

GO

PRINT 'Creating Procedure spFdsCNCreateUserHRDeptMap'
GO
/******************************************************************************
**		VSS File: $/spFdsCNCreateUserHRDeptMap.sql 
**		Name: spFdsCNCreateUserHRDeptMap    
**		Desc: 	This procedure creates a record in the 
**				PerHRDepartment_FwkDomainUser_Map table
**              
**		Return values: None
** 
**		Called by:   
**              
*******************************************************************************
**		Change History
*******************************************************************************
**		Date:		Author:				Description:
**		--------		--------				-------------------------------------------
**    
*******************************************************************************/
CREATE Procedure spFdsCNCreateUserHRDeptMap (
	/* Param List */
	@userId			INT,
	@hrDepartmentId	INT
)	   
AS    

BEGIN 

	SET NOCOUNT ON

	DECLARE @_errorCode		INT
	DECLARE @_perMapId		INT
	
	SET @_errorCode  = 0
	
	SET IDENTITY_INSERT PerHRDepartment_FwkDomainUser_Map ON
	
	-- Setup the IDs to be inserted by selecting the max
	-- Id of the column, and if null, start at 1.
	SET @_perMapId = COALESCE( ((SELECT MAX(Id) FROM PerHRDepartment_FwkDomainUser_Map)+1), 1)

	-- Insert the PerHRDepartment_FwkDomainUser_Map
	INSERT INTO PerHRDepartment_FwkDomainUser_Map	 (		Id, 
								FwkDomainUserId, 
								PerHRDepartmentId) 
	VALUES
							 (	@_perMapId, 
								@userId,			
								@hrDepartmentId)
	
	SET @_errorCode = @@ERROR
	
	SET IDENTITY_INSERT PerHRDepartment_FwkDomainUser_Map OFF

    IF @_errorCode <> 0 BEGIN
           RAISERROR('Unable to create PerHRDepartment_FwkDomainUser_Map record for User %s', 16, 1, @userId)
           RETURN @_errorCode
    END

END

GO
SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
